!------------------------------------------------------------------------------
! TJU/Department of Mechanics, Fluid Mechanics, Code START
!------------------------------------------------------------------------------
!> @Author: Jianxin Liu shookware@tju.edu.cn
!> @Date: 2024-12-05 13:34:27
!> @LastEditTime: 2024-12-05 13:38:48
!> @LastEditors: Jianxin Liu shookware@tju.edu.cn
!> @Description:
!> @FilePath: /chem/test/chem_transport.f90
!> @Copyright (c) 2024 by Jianxin Liu email: shookware@tju.edu.cn, All Rights Reserved.
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
! TJU/Department of Mechanics, Fluid Mechanics, Code START
!------------------------------------------------------------------------------
!> @Author: Jianxin Liu shookware@tju.edu.cn
!> @Date: 2024-12-05 13:34:27
!> @LastEditTime: 2024-12-05 13:36:06
!> @LastEditors: Jianxin Liu shookware@tju.edu.cn
!> @Description:
!> @FilePath: /test/chem_transport.f90
!> @Copyright (c) 2024 by Jianxin Liu email: shookware@tju.edu.cn, All Rights Reserved.
!------------------------------------------------------------------------------
program chem_transport_test

   use mod_chem
   use iso_fortran_env, only: dp => real64
   implicit none

   type(type_chem_phases) :: phases
   integer, parameter :: n = 1981
   real(dp), allocatable :: T(:), X(:, :), rho_compared(:), H, U
   real(dp) :: p = 101325.0_dp, rho

   integer :: l, i, ll

   integer :: file_io(100)

   phases = chem_file_load("air_5species_NASA9.yaml", "air")
   allocate (T(n), X(5, n), rho_compared(n))
   open (newunit=file_io(100), file="5S_P_xi.plt")
   read (file_io(100), *)
   read (file_io(100), *)
   do l = 1, n
      read (file_io(100), *) T(l), X(2, l), X(5, l), X(1, l), X(3, l), X(4, l), rho_compared(l)
   end do
   close (file_io(100))

   open (newunit=file_io(1), file="transport.plt")
   open (newunit=file_io(2), file="partial_viscosity.plt")
   open (newunit=file_io(3), file="partial_thermal_conductivity.plt")
   do l = 1, n
      call phases%set_state(T=T(l), X=X(1:5, l), P=p)
      write (file_io(1), '(1X, F20.4, 1X, 11G20.5)') T(l), phases%get_viscosity(), phases%get_thermal_conductivity(), &
         phases%get_viscosity()*phases%get_cp_mass()/phases%get_thermal_conductivity()
      write (file_io(2), '(1X, F20.4, 1X, 11G20.5)') T(l), phases%get_partial_viscosity()
      write (file_io(3), '(1X, F20.4, 1X, 11G20.5)') T(l), phases%get_partial_thermal_conductivity()
   end do
   close (file_io(1))
   close (file_io(2))
   close (file_io(3))
end
